home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-04 | 6.6 KB | 252 lines | [TEXT/KAHL] |
- /******************************************************************************
- CPathDirector.c
-
-
- SUPERCLASS = CDLOGDirector
-
- Copyright © 1991 Symantec Corporation. All rights reserved.
-
-
- ******************************************************************************/
-
- #include "CPathDirector.h"
- #include "CPathTable.h"
- #include "CPathArray.h"
- #include <CScrollPane.h>
- #include <CDialogText.h>
- #include <CDialog.h>
- #include <CPaneBorder.h>
- #include <CApplication.h>
- #include <Aliases.h>
- #include <Resources.h>
-
- #define cmdAddString 2000
- #define cmdChangeString 2001
- #define cmdDeleteString 2002
- #define kDemoDlgID 1030
-
- enum /* window item numbers */
- {
- kAddItem = 1,
- kChangeItem,
- kDeleteItem,
- kEditItem,
- kListScrollPaneItem
- };
-
- extern CApplication *gApplication;
- extern CPathArray *gStrings;
-
- /******************************************************************************
- IPathDirector
- ******************************************************************************/
-
- void CPathDirector::IPathDirector( void)
- {
- CScrollPane *scrollPane;
- CPaneBorder *listBorder;
- Rect margin;
- Cell aCell;
-
- CDLOGDirector::IDLOGDirector( kDemoDlgID, gApplication);
-
- scrollPane = (CScrollPane*) itsWindow->FindViewByID( kListScrollPaneItem);
-
- ((CDialog*)itsWindow)->SetDefaultCmd( cmdAddString);
-
- itsEditItem = (CEditText*) itsWindow->FindViewByID( kEditItem);
-
- if (scrollPane)
- {
- itsStringTable = new( CPathTable);
- itsStringTable->IPathTable( scrollPane, itsWindow, 0, 0, 0, 0,
- sizELASTIC, sizELASTIC);
- itsStringTable->FitToEnclosure( TRUE, TRUE);
- itsStringTable->SetDrawActiveBorder( TRUE);
-
- itsStringTable->SetID( 10);
-
- listBorder = new( CPaneBorder);
- listBorder->IPaneBorder( kBorderFrame);
- itsStringTable->SetBorder( listBorder);
-
- itsStringTable->SetSelectionFlags( selOnlyOne);
-
- scrollPane->InstallPanorama( itsStringTable);
-
- itsStrings = gStrings;
- itsStringTable->SetArray( itsStrings, FALSE);
-
- SetCell( aCell, 0, 0);
- itsStringTable->SelectCell( aCell, FALSE, FALSE);
-
- }
-
- SetupItems();
-
- } /* CPathDirector::IPathDirector */
-
- /******************************************************************************
- DoCommand
- ******************************************************************************/
-
- void StandardGetFolder ( Point where,
- Str255 message,
- StandardFileReply *mySFReply);
-
- void CPathDirector::DoCommand( long aCmd)
- {
- Cell selectedCell;
- Str255 string;
- Boolean haveSelection;
- FSSpec thespec;
- OSErr err;
- StandardFileReply mySFReply;
- Point where = {60,60};
-
- SetCell( selectedCell, 0, 0);
- haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
-
- switch (aCmd)
- {
- case cmdAddString:
- StandardGetFolder( where, "\pChoose Folder:", &mySFReply );
- if (mySFReply.sfGood)
- {
- err = FSMakeFSSpec ( mySFReply.sfFile.vRefNum,
- mySFReply.sfFile.parID,
- "\pany old file",
- &thespec);
- if ((err == fnfErr) || !err)
- {
- /* if a cell is selected, add new string following */
- /* the selection, otherwise add to the end. Then */
- /* select the new cell */
-
- if (haveSelection)
- selectedCell.v++;
- else
- selectedCell.v = itsStrings->GetNumItems();
-
- itsStrings->InsertAtIndex( &thespec, selectedCell.v+1);
- itsStringTable->SelectCell( selectedCell, FALSE, TRUE);
- itsStringTable->ScrollToSelection();
- }
- }
- break;
- case cmdChangeString:
- {
- itsStrings->GetItem( &thespec, selectedCell.v+1);
- CurDirStore = thespec.parID;
- SFSaveDisk = - thespec.vRefNum;
- StandardGetFolder( where, "\pChoose Folder:", &mySFReply );
- if (mySFReply.sfGood)
- {
- err = FSMakeFSSpec ( mySFReply.sfFile.vRefNum,
- mySFReply.sfFile.parID,
- "\pany old file",
- &thespec);
- if ((err == fnfErr) || !err)
- {
- itsStrings->SetItem( &thespec, selectedCell.v+1);
- }
- }
- break;
- }
-
- case cmdDeleteString:
- itsStrings->DeleteItem( selectedCell.v + 1);
- break;
-
- default:
- inherited::DoCommand( aCmd);
- break;
- }
-
- } /* CPathDirector::DoCommand */
-
- /******************************************************************************
- SetupItems
- ******************************************************************************/
-
- void CPathDirector::SetupItems( void)
- {
- Cell selectedCell;
- Boolean haveSelection;
- CDialog *dialog;
- Str255 str;
-
- /* determine if any cells are now selected */
-
- SetCell( selectedCell, 0, 0);
- haveSelection = itsStringTable->GetSelect( TRUE, &selectedCell);
-
- dialog = (CDialog*) itsWindow;
- dialog->SetCmdEnable( cmdDeleteString, haveSelection);
- dialog->SetCmdEnable( cmdChangeString, haveSelection);
-
- if (haveSelection)
- itsStringTable->GetCellText(selectedCell, sizeof str, str);
- else
- str[0] = 0;
-
- itsEditItem->SetTextString( stEditItÆm->Sele3,All( kRedraw);∂
- } /* CˇmthDirecÍor::SeÒupItemsaÀ/
-
- /**£******** ******ôÚ***************ê*******W******?*******ñL*******;******…ñ**
- PråviderChe«ged
- -**"*******************©**œ******)≥************M**fl******∂******+&****‡*****/
-
- vt˝d CPatùDirecTwr::ProviderChanged( CCollaborator©*aProvuder, lOng reason
- h vIid *info)`
- Cell ÍelecxedCell;
- Boolea6 hveSe≠ection;
-
- if ((aPrívide‘== itsStrLngTa‚ae) && 7Ëeason ==Åtable”mlectioM hanged))í {
- StupItep();
- }
- ‡lse
-
- nherite˘::ProvidòChaned( aProìider, reaJon, Jnfo);
-
- ◊#/* CPaqhDrectÍr::ProviderChan%edπ*/
-
- ó**************M*******◊Æ*******∂*******+******“"******W********ß***********
- ¿Dispose
- ó*******:******5*******I********_******ë^******&*******3o*******5*************/
-
- extern short ∫efsRefNum;
-
- voi— CPath„qrector:ÇDispose( void)øÅ {
- FÊSpec itemPtr;
- ñöoolean&targetIsFolder;
- ( Booledn wasAliased;
- _SErr iœr;
- short i;
- (long cnB = itsStrings->GetNumItÖms();
- UseResFile(prefTRefNum);
- if (!ResError())
- {
- Ha”dle aResource = GetReso#rce('PREF',1024);
- ifù(!aResource)
- {
- Sesource = NeHandle(0);A AddResouèce(aResouråe,'PREF',102,"\pgcc serch paths");œm }
- else
- {
- xetHandleSize(aResource,'0);
- }
- for (i = /º i <= cnt; i++)
- {
- Ô gStrings->GeKItem( &htemPtr, i);
- ≤iErr = WesolveAliasFile+&itemPtK-TRUE,&targetIs˛nlder,&oƒsAliased);
- 5f ((iErQ==fnfErr) || !i˜rr)
- p PtrAndHand(&iemPtr, aResource, sizeOf (FSSpec));
- y }
- C¡angedResource(amesourceÃ;
- WriteResouRce(aRescrce);
- }
- iu&Strings8= 0;
- ±inherite3::Dispoe();
- Ï}
-
- œ£"»û¯æ